"use strict";
cc._RF.push(module, 'd47bd8fwTZHt59jFXHv44sB', 'BlockItem');
// scripts/BlockItem.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _n4,
    i = void 0 && (void 0).__extends || (_n4 = function n(t, e) {
  return (_n4 = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _n4(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    s = void 0 && (void 0).__decorate || function (t, e, o, n) {
  var i,
      s = arguments.length,
      r = s < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, o) : n;
  if ("object" == (typeof Reflect === "undefined" ? "undefined" : typeof Reflect) && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, n);else for (var c = t.length - 1; c >= 0; c--) {
    (i = t[c]) && (r = (s < 3 ? i(r) : s > 3 ? i(e, o, r) : i(e, o)) || r);
  }
  return s > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("Global"),
    c = t("ResourceManager"),
    a = t("SDK"),
    u = cc._decorator,
    l = u.ccclass,
    d = u.property,
    p = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.headSprite = null, e.lockNode = null, e.tipsNode = null, e.bgNode = null, e.blockType = null, e.position = 0, e.game = null, e;
  }

  return i(e, t), e.prototype.onLoad = function () {
    var t = this;
    this.node.on(cc.Node.EventType.TOUCH_END, function () {
      t.onTouchEnd();
    }, this);
  }, e.prototype.init = function (t, e, o) {
    this.game = t, this.blockType = o, this.position = e, o.blockItem = this, this.loadInfo(!1);
  }, e.prototype.tips = function () {
    this.tipsNode.active = !0, cc.tween(this.node).to(0.2, {
      scale: 1.2
    }).to(0.1, {
      scale: 1
    }).to(0.2, {
      scale: 1.2
    }).to(0.1, {
      scale: 1
    }).start();
  }, e.prototype.loadInfo = function (t) {
    var e = this;

    if (0 == this.position) {
      if (t) {
        var o = 30 * this.blockType.x - 270,
            n = 300 - 30 * this.blockType.y;
        cc.tween(this.node).to(0.5, {
          x: o,
          y: n
        }).start();
      } else this.node.x = 30 * this.blockType.x - 270, this.node.y = 300 - 30 * this.blockType.y;
    } else 1 == this.position && (t ? (o = 0, o = 0 == this.blockType.x ? 45 + 10 * this.blockType.y : -45 - 10 * this.blockType.y, cc.tween(this.node).to(0.5, {
      x: o,
      y: 0
    }).start()) : (0 == this.blockType.x ? this.node.x = 45 + 10 * this.blockType.y : this.node.x = -45 - 10 * this.blockType.y, this.node.y = 0));

    c.ResourceMgr.getTextSprite(this.blockType.type, function (t) {
      e.headSprite && (e.headSprite.spriteFrame = t);
    }), this.reload();
  }, e.prototype.reload = function () {
    var t = this;
    this.blockType && (this.tipsNode && (this.tipsNode.active = !1), this.blockType.lowerThanBlocks.length > 0 ? (this.lockNode.active = !0, this.lockNode.opacity = 255, this.node.getComponent(cc.Button).interactable = !1) : (this.node.getComponent(cc.Button).interactable = !0, cc.tween(this.lockNode).to(0.2, {
      opacity: 0
    }).call(function () {
      t.lockNode.active = !1;
    }).start()));
  }, e.prototype.removeBindHigher = function () {
    for (var t = this.blockType.higherThanBlocks.length - 1; t >= 0; t--) {
      var e = this.blockType.higherThanBlocks[t];
      if (2 != e.status) for (var o = 0; o < e.lowerThanBlocks.length; o++) {
        e.lowerThanBlocks[o].id == this.blockType.id && (e.lowerThanBlocks.splice(o, 1), e.blockItem.reload());
      }
    }
  }, e.prototype.onTouchEnd = function () {
    var t = this;

    if (!(this.game.currSlotNum >= this.game.gameConfig.slotNum && !r["default"].unlimit || 1 != this.game._status || 0 != this.blockType.status || this.blockType.lowerThanBlocks.length > 0 && !this.game.openShengShou)) {
      this.game.gameWaitTime = 0, this.game.tipsWaitTime = 0, this.game.hasTips = !1, 1 == this.position && (this.bgNode.opacity = 255), this.blockType.status = 1, this.tipsNode.active = !1, this.node.stopAllActions(), this.node.scale = 1, this.game.opHistory.push(this.blockType), this.removeBindHigher();

      for (var e = !1, o = this.game.slotArea.length, n = 0; n < this.game.slotArea.length; n++) {
        for (var i = this.game.slotArea[n], s = this.game.texts.json, c = 0; c < s.length; c++) {
          var u = s[c].ps,
              l = u.indexOf(i.type),
              d = u.indexOf(this.blockType.type);

          if (l >= 0 && d >= 0) {
            o = d < l ? n : n + 1, e = !0;
            break;
          }
        }

        if (e) break;
      }

      this.game.slotArea.splice(o, 0, this.blockType), this.game.currSlotNum++, this.game.reloadSlot(this.blockType.id);
      var p = this.node.parent.convertToWorldSpaceAR(this.node.getPosition()),
          h = this.game.slotNode.convertToNodeSpaceAR(p);
      this.node.parent = this.game.slotNode, this.node.setPosition(h), cc.tween(this.node).to(0.2, {
        position: cc.v3(90 * o + 45, 0, 0)
      }).delay(0.1).call(function () {
        t.game.checkClear();
      }).start(), this.game.openShengShou && this.game.closeShengShou(), a["default"].vibrateShort();
    }
  }, e.prototype.start = function () {}, s([d(cc.Sprite)], e.prototype, "headSprite", void 0), s([d(cc.Node)], e.prototype, "lockNode", void 0), s([d(cc.Node)], e.prototype, "tipsNode", void 0), s([d(cc.Node)], e.prototype, "bgNode", void 0), s([l], e);
}(cc.Component);

o["default"] = p;

cc._RF.pop();